package com.breakfast.fun.ui.user.recharge.rechargexchangecode;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.breakfast.fun.R;
import com.breakfast.fun.base.BaseFragment;
import com.breakfast.fun.ui.user.recharge.rechargerecord.RechargeRecordActivity;
import com.breakfast.fun.util.T;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/8/24.
 */
public class RechargeExchangeCodeFragment extends BaseFragment<RechargeExchangeCodePresenter, RechargeExchangeCodeModel> implements RechargeExchangeCodeContract.View {

    @Bind(R.id.et_recharge_exchange_code)
    EditText mEtRechargeExchangeCode;
    @Bind(R.id.btn_recharge_exchange_code_sure)
    Button mBtnRechargeExchangeCodeSure;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_recharge_exchange_code;
    }

    @Override
    public void initView() {
        mBtnRechargeExchangeCodeSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(mEtRechargeExchangeCode.getText().toString().trim())) {
                    T.show("请输入兑换码");
                    return;
                }


                presenter.rechargeCode(mEtRechargeExchangeCode.getText().toString()
                );
            }
        });
    }

    @Override
    public void showSuccess() {
        T.show("充值成功");
        Intent intent = new Intent(getActivity(), RechargeRecordActivity.class);
        startActivity(intent);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
